//微信浏览器 h5 首页 防止返回关闭h5
window.addEventListener("popstate", function (e) {
	location.replace(location.href);
}, false);
function pushHistory() {
	var state = {
		title: "title",
		url: "#"
	};
	window.history.pushState(state, "title", "#");
}
pushHistory();

/**
 * 移动端过滤表情符号
 */
function filteremoji(content){
        var ranges = [
            '\ud83c[\udf00-\udfff]',
            '\ud83d[\udc00-\ude4f]',
            '\ud83d[\ude80-\udeff]'
        ];
        emojireg = content .replace(new RegExp(ranges.join('|'), 'g'), '');
        return emojireg;
}


/**
 * 将数字转换为两位数的字符//时间
 * @param {number} num
 * expiredTime为与当前时间相差得时间，separator为拼接的字符串
 * 可用于时间倒计时
 * */
function formatNumber(num) {
    var numStr = num.toString()
    return '00'.slice(0, 2 - numStr.length) + numStr
}
var Second = 1e3, Minute = 60 * Second, Hour = 60 * Minute
function getTimeleftStr(expiredTime, separator) {
    separator = separator === void 0 ? ': ' : separator
    var timeleft = Math.max(expiredTime - new Date().getTime(),0)
    var hour = Math.floor(timeleft / Hour)
    var minute = Math.floor((timeleft = timeleft - hour * Hour) / Minute)
    var second = Math.floor((timeleft = timeleft - minute * Minute) / Second)
    return [
        formatNumber(hour),
        formatNumber(Math.floor(minute)),
        formatNumber(Math.floor(second)),
    ].join(separator)
}
//数字val加count位小数
function numArrange(val,count){
    return Number(val).toFixed(count);
}
//获取链接参数name
function getQueryString(name) 
{
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
      return (r && r[2]) ? r[2] : null ;
}
//删除url参数值ref
function delQueStr(url, ref) 
{
    var str = "";

    if (url.indexOf('?') != -1)
        str = url.substr(url.indexOf('?') + 1);
    else
        return url;
    var arr = "";
    var returnurl = "";
    var setparam = "";
    if (str.indexOf('&') != -1) {
        arr = str.split('&');
        for (i in arr) {
            if (arr[i].split('=')[0] != ref) {
                returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&";
            }
        }
        return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1);
    }
    else {
        arr = str.split('=');
        if (arr[0] == ref)
            return url.substr(0, url.indexOf('?'));
        else
            return url;
    }
}
//时间戳转化
function add0(m){return m<10?'0'+m:m }
function getLocalTime(Number)
{
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(Number*1000);
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}